﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Data.SqlClient;

namespace CURDBase
{
    class CURDAdvance
    {
        /// <summary>
        /// 这是利用基础数据类执行命令
        /// </summary>
        public void Insert1()
        {
            // 定义SQL语句
            string sql = "insert into Employee(insert into Employee([EmployeeName], [Gender], [NowAddress], [IdCard], [Tel], [WeChat], [OtherWork], [EntryDate], [PostId], [DepartmentId])";
            // 利用占位符  字符串类型用 '' 包裹，数字类型不用
            sql += " values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8},{9})";

            // 获取数据，这里利用用户输入获取
            Console.Write("请输入员工姓名：");
            string employeeName = Console.ReadLine();
            Console.Write("请输入员工性别：");
            string gender = Console.ReadLine();
            Console.Write("请输入员工住址：");
            string nowAdress = Console.ReadLine();
            Console.Write("请输入员工身份证号：");
            string idCard = Console.ReadLine();
            Console.Write("请输入员工电话：");
            string tel = Console.ReadLine();
            Console.Write("请输入员工微信：");
            string weChat = Console.ReadLine();
            Console.Write("请输入员工其他职位：");
            string otherWork = Console.ReadLine();
            Console.Write("请输入员工入职日期：");
            string entryDate = Console.ReadLine();
            Console.Write("请输入员工职位编号：");
            int postId = int.Parse(Console.ReadLine());
            Console.Write("请输入员工部门编号：");
            int departmentId = int.Parse(Console.ReadLine());

            // 格式化
            sql = string.Format(sql, employeeName, gender, nowAdress, idCard, tel, weChat, otherWork, entryDate, postId, departmentId);
            int result = SQLHelperBase.ExecuteNonQuery(sql);
            Console.WriteLine("受影响的行数："+result);

        }

        public void Insert2()
        {
            string sql= "insert into Employee([EmployeeName], [Gender], [NowAddress], [IdCard], [Tel], [WeChat], [OtherWork], [EntryDate], [PostId], [DepartmentId])";
            // @ 是SQLServer的占位符/参数
            // 这里不能 @[EmployeeName]，即使下边相应的加 [] 也不行。
            sql += " values(@EmployeeName, @Gender, @NowAddress, @IdCard, @Tel, @WeChat, @OtherWork, @EntryDate, @PostId, @DepartmentId)";

            #region 获取数据
            // 获取数据，这里利用用户输入获取
            Console.Write("请输入员工姓名：");
            string employeeName = Console.ReadLine();
            Console.Write("请输入员工性别：");
            string gender = Console.ReadLine();
            Console.Write("请输入员工住址：");
            string nowAdress = Console.ReadLine();
            Console.Write("请输入员工身份证号：");
            string idCard = Console.ReadLine();
            Console.Write("请输入员工电话：");
            string tel = Console.ReadLine();
            Console.Write("请输入员工微信：");
            string weChat = Console.ReadLine();
            Console.Write("请输入员工其他职位：");
            string otherWork = Console.ReadLine();
            Console.Write("请输入员工入职日期：");
            string entryDate = Console.ReadLine();
            Console.Write("请输入员工职位编号：");
            int postId = int.Parse(Console.ReadLine());
            Console.Write("请输入员工部门编号：");
            int departmentId = int.Parse(Console.ReadLine());
            #endregion

            // 参数替换
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@EmployeeName",employeeName),
                new SqlParameter("@Gender",gender),
                new SqlParameter("@NowAddress",nowAdress),
                new SqlParameter("@IdCard",idCard),
                new SqlParameter("@Tel",tel),
                new SqlParameter("@WeChat",weChat),
                new SqlParameter("@OtherWork",otherWork),
                new SqlParameter("@EntryDate",entryDate),
                new SqlParameter("@PostId",postId),
                new SqlParameter("@DepartmentId",departmentId)
            };

            // 调用高级通用类执行
            int result = SQLHelperAdvance.ExecuteNonQuery(sql, parameters);
            Console.WriteLine("受影响的行数："+result);

        }


    }
}
